-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat]: Timesheet-Duration-Display #3352
Conversation
WalkthroughThe changes include a minor syntactical adjustment in the Changes
Possibly related PRs
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
apps/web/app/hooks/features/useTimelogFilterOptions.tsOops! Something went wrong! :( ESLint: 8.46.0 ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct. The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
apps/web/lib/features/task/task-displays.tsx (1)
67-98
: Consider creating a dedicated time-display moduleThe new time display components (
DisplayTimeForTimesheet
andTotalTimeDisplay
) seem to be more focused on time visualization rather than task-specific display logic. Consider moving them to a dedicated time-display module (e.g.,time-displays.tsx
) to:
- Better separate concerns
- Make these components reusable across different contexts
- Keep task-displays.tsx focused on task-specific display logic
apps/web/lib/features/integrations/calendar/table-time-sheet.tsx (1)
334-336
: Verify duration prop type and add error handlingWhile the dedicated component improves code organization, consider:
- Adding prop type validation for duration
- Handling cases where duration is undefined or invalid
<DisplayTimeForTimesheet - duration={task.timesheet.duration} + duration={task.timesheet.duration ?? 0} />
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
apps/web/app/hooks/features/useTimelogFilterOptions.ts
(1 hunks)apps/web/lib/features/integrations/calendar/table-time-sheet.tsx
(4 hunks)apps/web/lib/features/task/task-displays.tsx
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- apps/web/app/hooks/features/useTimelogFilterOptions.ts
🔇 Additional comments (4)
apps/web/lib/features/task/task-displays.tsx (1)
1-1
: LGTM! Import statements are well-structured
The new imports are appropriately organized and use well-maintained dependencies.
Also applies to: 5-6
apps/web/lib/features/integrations/calendar/table-time-sheet.tsx (3)
271-276
: LGTM! Improved code clarity and type safety
The changes enhance readability by using explicit return statements and proper type handling for the status.
58-58
: Verify component imports from task-displays module
The new time display components align with the PR objectives. Let's verify their implementation.
294-295
: Verify translation key and time calculation logic
The changes improve i18n support and encapsulate time calculation logic. However, let's verify:
- The translation key 'timer.TOTAL_HOURS' exists
- The TotalTimeDisplay component handles edge cases (empty array, null values)
✅ Verification successful
Let me gather more information about the TotalTimeDisplay component implementation since the previous search didn't show its details.
Let me try a different search pattern to find the TotalTimeDisplay component.
Translation key and component implementation verified successfully
The verification shows:
- The translation key 'timer.TOTAL_HOURS' exists in all language files under both apps/web/locales/ and apps/desktop/i18n/
- The TotalTimeDisplay component properly handles edge cases:
- Checks if timesheetLog is an array using Array.isArray()
- Provides fallback to 0 for non-array input
- Handles null/undefined duration with
totalDuration || 0
- Properly formats hours and minutes with padStart
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify translation key and component implementation
# Check for translation key
rg -g '*.json' '"TOTAL_HOURS"'
# Check TotalTimeDisplay implementation for edge cases
ast-grep --pattern 'export function TotalTimeDisplay({ $_ }) {
$$$
}'
Length of output: 2583
Script:
#!/bin/bash
# Search for TotalTimeDisplay component implementation
rg -g '*.{tsx,ts,jsx,js}' -B 2 -A 10 'TotalTimeDisplay.*=.*{'
Length of output: 171
Script:
#!/bin/bash
# Search for TotalTimeDisplay component implementation
rg -g '*.{tsx,ts,jsx,js}' -B 2 -A 10 'function TotalTimeDisplay'
# Alternative search in case it's defined as an arrow function
rg -g '*.{tsx,ts,jsx,js}' -B 2 -A 10 'const TotalTimeDisplay'
Length of output: 1219
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
apps/web/lib/features/task/task-displays.tsx (3)
1-6
: Maintain consistent quote style in importsThe
ClockIcon
import uses double quotes while other imports use single quotes.-import { ClockIcon } from "@radix-ui/react-icons" +import { ClockIcon } from '@radix-ui/react-icons';
68-74
: Add TypeScript return type for better type safetyThe
formatTime
helper function would benefit from explicit return type annotation.-const formatTime = (hours: number, minutes: number) => ( +const formatTime = (hours: number, minutes: number): JSX.Element => (
83-85
: Maintain consistent quote style in className attributesUse double quotes for consistency with other components in the file.
-<div className='flex items-center font-medium gap-x-1'> - <ClockIcon className='text-green-400 text-[14px] h-4 w-4' /> - <div className='flex items-center'> +<div className="flex items-center font-medium gap-x-1"> + <ClockIcon className="text-green-400 text-[14px] h-4 w-4" /> + <div className="flex items-center">
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
apps/web/lib/features/task/task-displays.tsx
(2 hunks)
🔇 Additional comments (2)
apps/web/lib/features/task/task-displays.tsx (2)
93-103
: Implementation looks good!
The component is well-implemented with:
- Proper memoization using React.memo
- Null safety in duration calculation
- Reuse of the formatTime helper
- Component displayName for debugging
76-103
: Verify the component usage in DataTableTimeSheet
Let's verify that these components are properly integrated in the DataTableTimeSheet component as mentioned in the AI summary.
✅ Verification successful
Components are properly integrated and used in DataTableTimeSheet
The verification confirms that both components are correctly imported and used in the table-time-sheet.tsx
file:
DisplayTimeForTimesheet
is used to show individual timesheet durationsTotalTimeDisplay
is used to display the total duration of timesheet logs- Both components are working with the expected props and data structure
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the usage of DisplayTimeForTimesheet and TotalTimeDisplay components
# Search for component imports and usage
echo "Checking component imports and usage..."
rg -l "DisplayTimeForTimesheet|TotalTimeDisplay" --type tsx
# Search specifically in DataTableTimeSheet component
echo "Checking DataTableTimeSheet implementation..."
rg -A 5 "DataTableTimeSheet" --type tsx
Length of output: 347
Script:
#!/bin/bash
# Description: Verify the usage of DisplayTimeForTimesheet and TotalTimeDisplay components
# Search for component imports and usage without file type restriction
echo "Checking component imports and usage..."
rg -l "DisplayTimeForTimesheet|TotalTimeDisplay"
# Search specifically in DataTableTimeSheet component
echo "Checking DataTableTimeSheet implementation..."
rg -A 10 "DataTableTimeSheet"
# Search for files that might contain these components
echo "Searching for potential component files..."
fd -e tsx -e ts -e jsx -e js
Length of output: 74670
Script:
#!/bin/bash
# Search for the usage of DisplayTimeForTimesheet and TotalTimeDisplay components in table-time-sheet.tsx
echo "Checking component usage in table-time-sheet.tsx..."
rg -A 5 "DisplayTimeForTimesheet|TotalTimeDisplay" "apps/web/lib/features/integrations/calendar/table-time-sheet.tsx"
# Search for any other potential usages of these components
echo "Checking other potential usages..."
rg -A 5 "DisplayTimeForTimesheet|TotalTimeDisplay" "apps/web/lib/features/task/task-displays.tsx"
Length of output: 2238
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
apps/web/lib/features/task/task-displays.tsx (4)
1-6
: Maintain consistent quote style in importsThe
ClockIcon
import uses double quotes while other imports use single quotes.-import { ClockIcon } from "@radix-ui/react-icons" +import { ClockIcon } from '@radix-ui/react-icons';
83-85
: Maintain consistent quote style in className attributesUse double quotes for consistency with other components in the file.
- <div className='flex items-center font-medium gap-x-1'> - <ClockIcon className='text-green-400 text-[14px] h-4 w-4' /> - <div className='flex items-center'> + <div className="flex items-center font-medium gap-x-1"> + <ClockIcon className="text-green-400 text-[14px] h-4 w-4" /> + <div className="flex items-center">
106-120
: Consider improving error handling and date comparisonsA few suggestions to enhance robustness and performance:
- Add error handling for invalid dates
- Consider timezone implications in date comparisons
- Move calculations outside JSX for better performance
export const TotalDurationByDate = React.memo( ({ timesheetLog, createdAt }: { timesheetLog: TimesheetLog[]; createdAt: Date | string }) => { - const targetDateISO = new Date(createdAt).toISOString(); + // Handle invalid dates + const targetDate = new Date(createdAt); + if (isNaN(targetDate.getTime())) { + console.warn('Invalid date provided to TotalDurationByDate'); + return null; + } + + // Move calculations outside JSX + const targetDateISO = targetDate.toISOString(); + + // Use UTC date comparison to avoid timezone issues const filteredLogs = timesheetLog.filter( - (item) => formatDate(item.timesheet.createdAt) === formatDate(targetDateISO)); + (item) => { + const itemDate = new Date(item.timesheet.createdAt); + return itemDate.toDateString() === targetDate.toDateString(); + }); + const totalDurationInSeconds = filteredLogs.reduce( (total, log) => total + (log.timesheet?.duration || 0), 0); const { h: hours, m: minutes } = secondsToTime(totalDurationInSeconds); + return ( <div className="flex items-center text-[#868688]"> {formatTime(hours, minutes)}
Line range hint
1-121
: Consider extracting shared types and constantsTo improve maintainability and reusability, consider:
- Creating a shared types file for timesheet-related interfaces
- Extracting time-related constants and utilities into a dedicated module
- Creating a shared styles object for common className combinations
This would help maintain consistency across the codebase and make future updates easier.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
apps/web/lib/features/integrations/calendar/table-time-sheet.tsx
(4 hunks)apps/web/lib/features/task/task-displays.tsx
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/web/lib/features/integrations/calendar/table-time-sheet.tsx
🔇 Additional comments (1)
apps/web/lib/features/task/task-displays.tsx (1)
68-74
: LGTM! Well-structured utility function
Good job extracting the common time formatting logic into a reusable function with proper typing.
@Innocent-Akim please work with @NdekoCode to carefully fix merge conflict as there is a lot of changes in one file you both did :( |
025c28b
to
fc23dca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
apps/web/lib/features/task/task-displays.tsx (4)
6-6
: Maintain consistent quote styleThe
ClockIcon
import uses double quotes while other imports use single quotes. Maintain consistency by using single quotes.-import { ClockIcon } from "@radix-ui/react-icons" +import { ClockIcon } from '@radix-ui/react-icons'
76-91
: Clean up className stylingThe component implementation looks good, but there are some style inconsistencies:
- Inconsistent quote style in className attributes
- Redundant
text-[14px]
alongsideh-4 w-4
- <div className='flex items-center font-medium gap-x-1'> - <ClockIcon className='text-green-400 text-[14px] h-4 w-4' /> - <div className='flex items-center'> + <div className="flex items-center font-medium gap-x-1"> + <ClockIcon className="text-green-400 h-4 w-4" /> + <div className="flex items-center">
106-121
: Consider optimizing date handling and performanceWhile the implementation is functional, consider these improvements:
- Date comparison might be affected by timezone differences. Consider using start/end of day comparisons.
- For large datasets, consider memoizing the filtered results.
export const TotalDurationByDate = React.memo( ({ timesheetLog, createdAt }: { timesheetLog: TimesheetLog[]; createdAt: Date | string }) => { - const targetDateISO = new Date(createdAt).toISOString(); + const targetDate = new Date(createdAt); + const startOfDay = new Date(targetDate.setHours(0, 0, 0, 0)); + const endOfDay = new Date(targetDate.setHours(23, 59, 59, 999)); + + // Memoize filtered logs + const filteredLogs = React.useMemo(() => timesheetLog.filter((item) => { - formatDate(item.timesheet.createdAt) === formatDate(targetDateISO) + const logDate = new Date(item.timesheet.createdAt); + return logDate >= startOfDay && logDate <= endOfDay; }), + [timesheetLog, startOfDay, endOfDay] + );
Line range hint
1-121
: Good architectural decisions and component structureThe file demonstrates good architectural decisions:
- Clear separation of concerns between display components
- Proper use of memoization for performance
- Good extraction of common functionality
- Consistent error handling
Consider creating a separate utilities file for time-related functions if more time manipulation logic is added in the future.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
apps/web/app/hooks/features/useTimelogFilterOptions.ts
(1 hunks)apps/web/lib/features/integrations/calendar/table-time-sheet.tsx
(4 hunks)apps/web/lib/features/task/task-displays.tsx
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/web/app/hooks/features/useTimelogFilterOptions.ts
- apps/web/lib/features/integrations/calendar/table-time-sheet.tsx
🔇 Additional comments (2)
apps/web/lib/features/task/task-displays.tsx (2)
68-74
: LGTM! Well-structured utility function
Good job extracting the common time formatting logic into a reusable function. This reduces code duplication and maintains consistency across components.
93-103
: LGTM! Well-implemented memoized component
The component is well-structured with:
- Proper memoization for performance
- Null-safe duration calculation
- Type-safe props
- Reuse of formatTime utility
Description
Please include a summary of the changes and the related issue.
#3043
Type of Change
Checklist
Previous screenshots
Please add here videos or images of previous status
Current screenshots
Please add here videos or images of previous status
Summary by CodeRabbit
New Features
DisplayTimeForTimesheet
,TotalTimeDisplay
, andTotalDurationByDate
components for enhanced time display in timesheets.DataTableTimeSheet
component to dynamically show total hours and task durations.Bug Fixes
useTimelogFilterOptions
to improve code readability without affecting functionality.Documentation